const {app, BrowserWindow} = require("electron")
const isDev = require("electron-is-dev")
const path = require('path')

app.on('ready', () => {
  let mainWindow = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      nodeIntegration: true
    },
    show: false
  })
  mainWindow.loadURL(isDev ? "http://localhost:3000" : `file://${path.join(__dirname, './index.html')}`)
  .then(() => {
    mainWindow.show()
  })
  // Sometimes it doesn't trigger
  // mainWindow.once('ready-to-show', () => {
  //   mainWindow.show()
  // })
  mainWindow.on('closed', () => {
    mainWindow = null
  })
})